/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#ifndef MK_HTTP_MESSAGE_H
#define MK_HTTP_MESSAGE_H
#include "MkUtil/MkTypes.h"

class MkApi CMkHttpMessage
{
public:
    CMkHttpMessage();
    virtual ~CMkHttpMessage();

    Uint32 Parse(const Uint8* pBuf, Uint32 nLen, Uint32& nUsed);
    const MkString& GetVersion() const { return m_Version; }
    BOOL IsConnectClose() const;
    Uint32 ToString(MkString& Content);
    const Uint64& GetSessionId() const { return m_HttpSessionId; }
    const MkString& GetBody() const { return m_Body; }
    void SetSessionId(const Uint64& SessionId) { m_HttpSessionId = SessionId; }

    Uint32 GetHeadValue(const MkString& Key, MkString& Value) const;
    Uint32 AddHeader(const MkString& Key, const MkString& Value);
    Uint32 SetVersion(const MkString& Version);
    virtual Uint32 OnParseHeaderLine(const MkString& HeaderLine) = 0;
    virtual Uint32 GetHeaderLine(MkString& HeaderLine) = 0;
    virtual void Release();
protected:
    Uint32 ParseHeader(const MkString& strHeader, MkString& Key, MkString& Value);
    Uint32 GetBodySize();
private:
    MkMultiMap<MkString, MkString>      m_Headers;
    MkString                            m_Version;
    MkString                            m_Body;
    BOOL                                m_ParseHeaderEnd;
    Uint32                              m_BodySize;
    BOOL                                m_bChunkedBody;
    Uint64                              m_HttpSessionId;
};


#endif